<template>
  <div>
        <el-button type="primary" @click="onsubmit">创建</el-button>
    <el-form :model="leasePayment" label-width="80px" class="forma">
      <el-row>
        <el-col :span="6">
          <el-form-item label="日期">
            <el-input type="date" v-model="leasePayment.applyDate"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="付款编号">
            <el-input v-model="leasePayment.id" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="付款名称">
            <el-input v-model="leasePayment.paymentName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="所属项目">
            <el-input
              v-model="leasePayment.projectName"
              @focus="ProjectName"
            ></el-input>
            <el-input v-model="leasePayment.pid" v-if="false"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="租赁合同">
            <el-input
              v-model="leasePayment.contractName"
              @focus="LeaseContractlist"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6"> </el-col>
        <el-col :span="6">
          <el-form-item label="合同金额">
            <el-input v-model="leasePayment.contractAmount" ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="金额大写">
            <el-input v-model="leasePayment.agreeUpper"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="供应商">
            <el-input v-model="leasePayment.companyName" @focus="getCompanyName"></el-input>
          </el-form-item>
        </el-col>
      
      </el-row>

      <el-row>
        <el-col :span="6">
          <el-form-item label="签订人">
            <el-input v-model="leasePayment.handlerName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="付款说明">
            <el-input v-model="leasePayment.settleComment" type="textarea"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="相关文件:" style="width: 700px; height: 80px">
        <!-- 文件上传 -->
        <multi-file-upload
          style="width: 90%; margin: 20px auto"
          title="附件"
          action="http://localhost/uploads"
          :params="{ folder: 'LeasePayment' }"
          :headers="{ token: this.$store.state.token }"
          @uploadSuccess="handleUploadSuccess"
          :parent-file-list="fileList"
        ></multi-file-upload>
      </el-form-item>
    </el-form>

    <el-dialog :visible.sync="projectTableVisible">
      <project-info-list
        v-on:row="row"
        v-if="projectTableVisible"
      ></project-info-list>
    </el-dialog>
    <el-dialog :visible.sync="materTableVisible">
      <material-list v-on:checked="checked"></material-list>
    </el-dialog>
    <el-dialog :visible.sync="leaseTableVisible">
      <el-table
        :data="leaseContracts"
        height="250"
        border
        style="width: 100%"
        @row-click="aaa"
      >
        <el-table-column prop="id" label="合同编号" width="180">
        </el-table-column>
        <el-table-column prop="contractName" label="合同名称" width="180">
        </el-table-column>
        <el-table-column prop="contractAmount" label="合同金额">
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog :visible.sync="subCommanyTableVisible">
      <el-table
        :data="subCommany"
        height="250"
        border
        style="width: 100%"
        @row-click="bbb"
      >
        <el-table-column prop="companyId" label="供应商编号" width="180">
        </el-table-column>
        <el-table-column prop="companyName" label="供应商名称" width="180">
        </el-table-column>
      </el-table>
    </el-dialog>
   
  </div>
</template>

<script>


import ProjectInfoList from "../common/projectInfo/ProjectInfoList.vue";
import MaterialList from "../common/material/MaterialList.vue";
import leasePayment from '../../model/hyh/LeasePayment'
const lp=new leasePayment()
export default {
  components: { ProjectInfoList, MaterialList },
  data() {
    return {
      headers: { token: sessionStorage.getItem("token") },
      uploadUrl: "http://localhost/upload",
      username: { realName: sessionStorage.getItem("realName")},
      leaseContracts: [],

      leasePayment: {},
      subCommany:[],
      projectTableVisible: false,
      materTableVisible: false,
      leaseTableVisible: false,
      subCommanyTableVisible:false,
      currentIndex: "",
      fileList: [],
    };
  },
  methods: {
      //查询最大付款编号
      getMaxid(){
     lp.getMaxid().then((response)=>{
         this.leasePayment.id=response.data.data
         console.log(response.data.data)
     })
    
      },
      //获取供应商
      getCompanyName(){
        lp.getCompanyName().then((response)=>{
         this.subCommany=response.data
        })
        this.subCommanyTableVisible=true
      },
bbb(row){
this.leasePayment.companyId=row.companyId
this.leasePayment.companyName=row.companyName
console.log(this.leasePayment.companyId)
this.subCommanyTableVisible=false
},



      
        aaa(row){
            this.leasePayment.contractName=row.contractName
            this.leasePayment.ctrId=row.id
            this.leasePayment.contractAmount=row.contractAmount
        this.leaseTableVisible=false
        },
      //查询租赁合同信息
    LeaseContractlist() {
         lp.getLeasecontract().then((response)=>{
             this.leaseContracts=response.data
         })
      this.leaseTableVisible = true;
    },

    handleUploadSuccess(ids) {
      this.leasePayment.attachIds = ids;
    },

    checked(checked) {
      this.leaseContractDetail = false;
      this.leaseContractDetail = checked;

      console.log(this.leaseContractDetail);
    },

    row(row) {
      this.projectTableVisible = false;
      this.leasePayment.projectName = row.projectName;
      this.leasePayment.pid = row.id;
      console.log(this.leasePayment.pId);
    },
    //查询项目信息
    ProjectName() {
      this.projectTableVisible = true;
    },

    onsubmit(){
        lp.saveLeasePayment(this.leasePayment).then(()=>{
            this.$message("添加成功")
        })
        console.log(this.leasePayment)
    }






  },
  created() {
  this.getMaxid()
    this.leasePayment.handlerId = this.username.realName;

  },
};
</script>

<style>
</style>